package com.shyroke.common;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonConvert {  
	  
    /** 
     * @param args 
     * @throws IOException 
     */  
    public static void changeUrl(String url) throws IOException {  
        // 读取原始json文件并进行操作和输出  
    	 FileWriter writer = null; 
        try {  
      
            String s = null, ws = null;  
                try {  
                	File file=new File("D:\\eclipse_workspace\\persion_library\\src\\main\\webapp\\script\\utf8-jsp\\jsp\\config.json");
                    String content= FileUtils.readFileToString(file,"UTF-8");
                    JSONObject dataJson=new JSONObject(content);
                    dataJson.remove("imageManagerListPath");
                    dataJson.put("imageManagerListPath", url);
                    dataJson.remove("snapscreenPathFormat");
                    dataJson.put("snapscreenPathFormat", url);
                    dataJson.remove("scrawlPathFormat");
                    dataJson.put("scrawlPathFormat", url);
                    dataJson.remove("catcherPathFormat");
                    dataJson.put("catcherPathFormat", url);
                    dataJson.remove("imagePathFormat");
                    dataJson.put("imagePathFormat", url);
                    ws = dataJson.toString();  
                    
                    writer = new FileWriter("D:\\eclipse_workspace\\persion_library\\src\\main\\webapp\\script\\utf8-jsp\\jsp\\config.json", false);     
                    writer.write(ws); 
                 
                    System.out.println(ws);  
                } catch (JSONException e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
                }  
  
  
        } catch (IOException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
        writer.close();
    }  
  
}  
